package cn.tedu.carehome.foundation.controller;

import cn.tedu.carehome.foundation.pojo.dto.BedAddNewDTO;
import cn.tedu.carehome.foundation.pojo.dto.BedUpdateDTO;
import cn.tedu.carehome.foundation.pojo.vo.BedAdminListVO;
import cn.tedu.carehome.foundation.pojo.vo.BedAdminStandardVO;
import cn.tedu.carehome.foundation.pojo.vo.BedAdminUpdateStandardVO;
import cn.tedu.carehome.foundation.pojo.vo.BedStaffVO;
import cn.tedu.carehome.foundation.service.IBedService;
import cn.tedu.carehome.foundation.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Api("床位分配管理")
@Validated
@RestController
@RequestMapping("/bed")

public class BedController {


    @Autowired
    IBedService bedService;

    @ApiOperation("添加床位")
    @PostMapping("/add-new")
    public  JsonResult<Void> addNew(@Validated BedAddNewDTO bedAddNewDTO){
        log.debug("添加数据：{}",bedAddNewDTO);
        bedService.addNew(bedAddNewDTO);
        return   JsonResult.ok();
    }

    @ApiOperation("床位信息查询")
    @GetMapping("/{floor:[0-9]+}/list")
    public List<BedAdminListVO> list(@Range(max = 20,min = 1,message = "楼层号非法！") @PathVariable int floor)
    {
        return bedService.list(floor);
    }

    @ApiOperation("根据id床位信息查询")
    @GetMapping("/{id:[0-9]+}/getStandard")
    public JsonResult<BedAdminStandardVO> getStandardByid(@Range(min = 1,message = "id非法！") @PathVariable Long id)
    {
        return JsonResult.ok(bedService.getStandardByid(id));
    }

    @ApiOperation("根据id床位以及入住信息查询")
    @GetMapping("/{id:[0-9]+}/upgetStandByid")
    public JsonResult<BedAdminUpdateStandardVO> upgetStandByid(@Range(min = 1,message = "id非法！")@PathVariable Long id)
    {
        return JsonResult.ok(bedService.upStandarByid(id));
    }
    @ApiOperation("床位楼层查询")
    @GetMapping("/floor-list")
    public  List<Integer> StandarFloor()
    {
        return bedService.StandarFloor();
    }

      @ApiOperation("根据id删除床位")
    @PostMapping("/{id:[0-9]+}/deleteByid")
    public JsonResult deleteByid(@Range(min = 1,message = "id非法！") @PathVariable("id") Long id)
      {
          bedService.deleteByid(id);
          return JsonResult.ok();
      }

      @ApiOperation("根据入住id退床功能")
    @PostMapping("/{checkId:[0-9]+}/{id:[0-9]+}/deleteBycheckId")
    public  JsonResult deleteBycheckId(@Range(min = 1,message = "id非法！") @PathVariable("checkId") Long checkId,@Range(min = 1,message = "id非法！") @PathVariable("id") Long id){
        bedService.deleteBycheckId(checkId,id);
      return   JsonResult.ok();
      }

    @GetMapping("/staffList")
    public JsonResult<List<BedStaffVO>> staffList()
    {
        log.debug("{}",bedService.staffList());
        return JsonResult.ok(bedService.staffList());
    }

    @PostMapping("/update")
    public JsonResult<Void> update(@Validated  BedUpdateDTO bedUpdateDTO)
    {
        bedService.update(bedUpdateDTO);
        return JsonResult.ok();
    }
}
